import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageResize {

	/**
	 *  args0 原图片路径,args1 新图片路径,args2 新图片宽度, arg3 新图片高度
	 *
	 * @param args
	 */

	public static void main(String[] args) {

		if(args == null || args.length != 4) {
			return;
		}
		try {

			resizeImage(args[0],args[1],Integer.parseInt(args[2]),Integer.parseInt(args[3]));

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void resizeImage(String srcImgPath, String distImgPath,
								   int width, int height) throws IOException {

		File srcFile = new File(srcImgPath);
		Image srcImg = ImageIO.read(srcFile);
		BufferedImage buffImg = null;
		buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		buffImg.getGraphics().drawImage(
				srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0,
				0, null);

		ImageIO.write(buffImg, "PNG", new File(distImgPath));
	}
}
